#include "../pch.h"

namespace BFX
{

REFXMLDeclaration::REFXMLDeclaration(const UniString& strVersion, const UniString& strEncoding, const UniString& strStandalone, REFXMLDocument* pDoc)
{
	BFX_ENSURE(strVersion == USTR("1.0"));
	BFX_ENSURE(strStandalone.IsEmpty() || strStandalone == USTR("yes") || strStandalone == USTR("no"));

	m_strVersion	= strVersion;
	m_strEncoding	= strEncoding;
	m_strStandalone	= strStandalone;
}
REFXMLDeclaration::~REFXMLDeclaration()
{
}

// The version attribute (1.0) for <?xml version= '1.0' ... ?>
UniString REFXMLDeclaration::GetVersioin() const
{
	return m_strVersion;
}
// Specifies the value of the encoding attribute, as for <?xml version= '1.0' encoding= 'UTF-8' ?>
UniString REFXMLDeclaration::GetEncoding() const
{
	return m_strEncoding;
}
void REFXMLDeclaration::SetEncoding(const UniString& strEncoding)
{
	m_strEncoding = strEncoding;
}

// Specifies the value of the standalone attribute.
UniString REFXMLDeclaration::GetStandalone() const
{
	return m_strStandalone;
}
void REFXMLDeclaration::SetStandalone(const UniString& strStandalone)
{
	m_strStandalone = strStandalone;
}

//
// Overrides
//
UniString REFXMLDeclaration::GetValue() const
{
	return GetInnerText();
}
void REFXMLDeclaration::SetValue(const UniString& strValue)
{
	SetInnerText(strValue);
}

// Gets or sets the concatenated values of the node and all its children.
UniString REFXMLDeclaration::GetInnerText() const
{
	UniString strResult;
	strResult.Append(USTR("version=\""));
	strResult.Append(m_strVersion);
	strResult.Append(USTR("\""));
	if (!m_strEncoding.IsEmpty())
	{
		strResult.Append(USTR(" encoding=\""));
		strResult.Append(m_strEncoding);
		strResult.Append(USTR("\""));
	}
	if (!m_strStandalone.IsEmpty())
	{
		strResult.Append(USTR(" standalone=\""));
		strResult.Append(m_strStandalone);
		strResult.Append(USTR("\""));
	}
	return strResult;
}
void REFXMLDeclaration::SetInnerText(const UniString& strText) const
{
	// TODO:
	BFX_ASSERT(false);
}

// Gets the name of the node.
UniString REFXMLDeclaration::GetName() const
{
	return USTR("xml");
}
// Gets the name of the current node without the namespace prefix.
UniString REFXMLDeclaration::GetLocalName() const
{
	return GetName();
}

// Gets the type of the current node.
XMLNodeType REFXMLDeclaration::GetNodeType() const
{
	return XMLNodeType_XmlDeclaration;
}

// Saves the node to the specified XmlWriter.
void REFXMLDeclaration::WriteTo(REFXMLWriter* w) const
{
	w->WriteProcessingInstruction(GetName(), GetInnerText());
}
// Saves all the children of the node to the specified XmlWriter.
void REFXMLDeclaration::WriteContentTo(REFXMLWriter* w) const
{
	// NOTE: intentionally do nothing since the node doesn't have children.
}

}	//	namespace BFX
